

package com.mercury.security.config;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Primary;
import org.springframework.security.oauth2.provider.token.ResourceServerTokenServices;
import org.springframework.security.oauth2.provider.token.TokenStore;

/**
 * 资源服务器 自动配置
 *
 * @author mercury
 */
@EnableConfigurationProperties(PermitAllUrlProperties.class)
public class AuthResourceServerAutoConfiguration {

    @Bean("pms")
    public PermissionService permissionService() {
        return new PermissionService();
    }


    @Bean
    public AuthBearerTokenExtractor authBearerTokenExtractor(PermitAllUrlProperties urlProperties) {
        return new AuthBearerTokenExtractor(urlProperties);
    }


    @Bean
    public AuthResourceExceptionEntryPoint resourceAuthExceptionEntryPoint(ObjectMapper objectMapper) {
        return new AuthResourceExceptionEntryPoint(objectMapper);
    }

    @Bean
    @Primary
    public ResourceServerTokenServices resourceServerTokenServices(TokenStore tokenStore) {
        return new AuthLocalResourceServerTokenServices(tokenStore);
    }


}
